package org.apache.ocean;

/**
 *
 * @author jasonr
 */
public class ConditionWait<V> {
  private Met<V> met;
  
  public ConditionWait(long waitDuration, long delay, Condition condition) throws Exception, GeneralTimeoutException {
    TimeoutState timeoutState = new TimeoutState();
    
  }
  
  public ConditionWait(TimeoutState timeoutState, long delay, Condition condition) throws Exception, GeneralTimeoutException {
    while (true) {
      met = condition.isMet();
      if (met != null) return;
      if (timeoutState.notOK()) throw new GeneralTimeoutException(timeoutState);
      Thread.sleep(delay);
    }
  }
  
  public V returnObject() {
    return met.object;
  }
  
  public static class Met<V> {
    public V object;
    
    public Met() {}
    
    public Met(V object) {
      this.object = object;
    }
  }
  
  public static interface Condition<V> {
    public Met<V> isMet() throws Exception;
  }
}
